--过载速射
local guozaisushe = fk.CreateSkill {
    name = "mcdh_guozaisushe"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

guozaisushe:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return  player:hasSkill(self) and player == target and target.phase == Player.Play
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local choices = {}
        for i = 1, player:getMark("mcdh_ammo"), 1 do
            table.insert(choices, tostring(i))
        end
        table.insert(choices,"Cancel")
        local choice = room:askForChoice(target, choices, self.name,"#guozaisushe")
        if choice ~= "Cancel" then
            self.cost_data = tonumber(choice)
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local num = self.cost_data
        lib.LoseAmmo(player,player,num,self.name)
        local cards = room:getNCards(num)
        room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
        local Nonbasic = table.filter(cards,function(id) return Fk:getCardById(id).type ~= Card.TypeBasic  end)
        room:moveCardTo(Nonbasic, Player.Hand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        cards = table.filter(cards,function(id) return not table.contains(Nonbasic,id)  end)

        if #cards > 0 then
            room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
        end
        for i = 1, #cards, 1 do
            if player.dead or #U.getDefaultTargets(player,Fk:cloneCard("slash"),true,false) == 0 then break end
            U.askForUseVirtualCard(room, player, "slash", nil, self.name, "#guozaisushe-use:::"..i..":"..#cards, false, true, false, true)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_guozaisushe"] = "过载速射",
    [":mcdh_guozaisushe"] = "装填技(X)，出牌阶段开始时，你可以亮出牌堆顶X张牌并获得其中的非基本牌，然后视为使用其中基本牌数量张不计入次数的【杀】。",
    ["#guozaisushe"] = "过载速射: 选择你要射击的子弹数量",
    ["#guozaisushe-use"] = "过载速射: 视为使用【杀】。（第%arg张，共%arg2张）"
}

return guozaisushe